<?php
class Myblog_Form_UserProfile extends Zend_Form
{
public $formDecorators=array(
array('FormElements'),
array('Form')
);
public $elementDecorators=array(
array('ViewHelper'),
array('Label'),
array('Errors'),
array('HtmlTag',array('tag'=>'div','class'=>'element')));
public $inputDecorators=array(
array('ViewHelper'),
array('Label'),
array('Errors'),
array('HtmlTag',array('tag'=>'div','class'=>'inputelement'))
);
public $avatarDecorators=array(
array('ViewHelper'),
array('Label',array('tag'=>'div')),
array('Errors'),
array('HtmlTag',array('tag'=>'div','id'=>'avatar')),

);

	public function init()
		{
		$this->setAction('user/editprofile') //
				->setMethod('POST')
				->setName('userprofile')
				->setAttrib('enctype','multipart/form-data')
				->setAttrib('onsubmit','return checkform()')
				->setDecorators($this->formDecorators);
		
		$this->addElements(array(
		
		new Zend_Form_Element_Text('userlogin', array(
			'label'=>'Логин:',
			'required'=>true,
			'size'=>'15',
			'maxlength'=>'20',
			'validators'=>array(array('NotEmpty'),
										array('Alnum'),
										array('LoginUnique')),	
																
				'filters'=>	array(array('StripTags'),
										array('StringTrim'),
										array('StringToLower')),

			'decorators'=>$this->elementDecorators
		)),
		new Zend_Form_Element_Text('username',array(
			'label'=>'Имя:',
			'required'=>true,
			'size'=>'15',
			'maxlength'=>'20',
			'validators'=>array(array('NotEmpty'),
										array('NameValidator')),
				
				'filters'=>	array(array('StripTags'),
										array('StringTrim')),
								//	array('StringToLower')),//проблемы с киррилицей
			'decorators'=>$this->inputDecorators
		)),
		new Zend_Form_Element_Text('email', array(
			'label'=>'Email:',
			'required'=>true,
			'size'=>'15',
			'maxlength'=>'25',
            'style'=>'margin-left:5px;',
			'validators'=>array(array('NotEmpty'),
										array('EmailAddress'),
										array('EmailUnique')),
				'filters'=>	array(array('StripTags'),
										array('StringTrim'),
										array('StringToLower')),
			'decorators'=>$this->elementDecorators
		)),
		
	
		
		new Zend_Form_Element_Image('avatar',array(
  			'label'=>'Аватар:',
            'min-height'=>'50px',
            'max-height'=>'100px',

  			'src'=>'/images/avatars/noavatar.png',
  			'decorators'=>$this->avatarDecorators
		)),

		$file = new Zend_Form_Element_File('image', array(
				'label'=>'Изменить аватар',
				'destinations'=>'images/avatars/',
				'size'=>'16',
                'required'=>false,
                'validators'=>array(
                    array('isImage'),
                    array('Extension',false,array('jpg','jpeg','png','gif')),
                    array('Count',false,2),
                    array('FilesSize',false,array('min' => '5kB', 'max' => '2MB')),
                    array('ImageSize',false,array('minwidth'=>50,'maxwidth'=>1920,
                                                  'minheight'=>50,'maxheight'=>1080))
                ),
		)),
		new Zend_Form_Element_Submit('submit',array(
			'label'=>'Сохранить',
			'class'=>'btn btn-primary',
		))
		
		));

		$this->addDisplayGroup(array('username','userlogin','email','avatar','image','submit'),'authDataGroup',array('legend'=>'Личные данные'));
		}
}
?>
